<template>
	<view class="content">
		 
		 
		 <view class="btn" @click="tologin">
 			<text>微信授权一键登录</text>
		 </view>
	</view>
</template>

<script>
	import {loginAPI} from "@/api/login.js"
	import {profileAPI} from "@/api/api.js"
	export default {
		data() {
			return {
				invite_code:""
			}
		},
		onLoad(option) {
			if(option.scene){
				var url=decodeURIComponent(decodeURIComponent(option.scene));
			  
				this.invite_code=url.split("=")[1]
				console.log(this.invite_code)
			}
		
		},
		methods: {
			tologin(){
				var _this=this
				uni.login({
				  provider: 'weixin', //使用微信登录
				  success: function (loginRes) {
				    console.log(loginRes);
					var data={
						js_code:loginRes.code
					}
					if(_this.invite_code){
						data.invite_code=_this.invite_code
						 
					}
					loginAPI(data).then(result=>{
						uni.setStorageSync("token",result.token)
						uni.setStorageSync("is_phone",result.is_phone)
						if (result.is_phone==0) {
							_this.tourl("/pages/register/choseType")
						} else{
							
							profileAPI().then(res=>{
								uni.setStorageSync("user_role",res.user_role)
								uni.reLaunch({
									url:'/pages/home/home'
								})
							})
							
						}
						
					})
				  }
				});
				 
			}
		}
	}
</script>

<style lang="scss">
.content{
	display: flex;
	flex-direction: column;
	height: 100vh;
	justify-content: space-around;
	align-items: center;
	.btn{
		background: linear-gradient(98deg,#ff5e18, #ff1818 100%);
		border-radius: 12px;
		width: 520rpx;
		display: flex;
		align-items: center;
		justify-content: center;	
		 
		padding: 20rpx;
		image{
			width: 50rpx;
		}
		text{
			color: #fff;
			margin-left: 10px;
		}
	}
	
}
</style>
